<template>
  <div class="recent-treatments" v-loading="loading">
    <el-table :data="treatments" :show-header="true" style="width: 100%">
      <el-table-column prop="user_id" label="用户ID" width="120">
      
      </el-table-column>
      
      <el-table-column prop="device_id" label="设备ID" width="150" />
      
      <el-table-column prop="treatment_mode" label="治疗模式" width="120" >
 
        
        <template #default="{ row }">
          <el-tag :type="getModeType(row.treatment_mode)">
            {{ getModeText(row.treatment_mode) }}
          </el-tag>
        </template>
      </el-table-column>
           <el-table-column prop="frequency" label="频率hz" width="120" />
      <el-table-column prop="current_intensity" label="电流mA" width="120"/>
      <el-table-column prop="treatment_duration" label="时间/分" width="120"/>
      
      <el-table-column prop="start_time" label="开始时间" width="160">
        <template #default="{ row }">
          {{ formatDate(row.start_time) }}
        </template>
      </el-table-column>
      
      <el-table-column prop="status" label="状态" width="100">
        <template #default="{ row }">
          <el-tag :type="getStatusType(row.status)">
            {{ getStatusText(row.status) }}
          </el-tag>
        </template>
      </el-table-column>
      
      <!-- <el-table-column label="操作" width="100">
        <template #default="{ row }">
          <el-button size="small" type="primary" @click="viewDetail(row.id)">
            详情
          </el-button>
        </template>
      </el-table-column> -->
    </el-table>
    
    <div v-if="treatments.length === 0 && !loading" class="no-data">
      暂无治疗记录
    </div>
  </div>
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router'
import { formatDate } from '@/utils/format'

interface Treatment {
  id: number
  user_id: number
  user_nickname?: string
  user_avatar?: string
  device_id: string
  treatment_mode: string
  treatment_duration: number
  current_intensity: number
  frequency: number
  status: string
  start_time: string
  end_time: string
  actual_duration: number
  effectiveness_score: number | null
  notes: string
  created_at: string
}

interface Props {
  treatments: Treatment[]
  loading?: boolean
}

const props = withDefaults(defineProps<Props>(), {
  treatments: () => [],
  loading: false
})

const router = useRouter()

const getModeType = (mode: string) => {
  const types: Record<string, string> = {
    'tDCS+': 'primary',
    'tDCS-': 'success',
    'tACS': 'warning'
  }
  return types[mode] || 'info'
}

const getModeText = (mode: string) => {
  return mode
}

const getStatusType = (status: string) => {
  const types: Record<string, string> = {
    'completed': 'success',
    'interrupted': 'warning',
    'ongoing': 'primary'
  }
  return types[status] || 'info'
}

const getStatusText = (status: string) => {
  const texts: Record<string, string> = {
    'completed': '已完成',
    'interrupted': '已中断',
    'ongoing': '进行中'
  }
  return texts[status] || status
}

const viewDetail = (treatmentId: number) => {
  router.push(`/treatments/detail/${treatmentId}`)
}
</script>

<style scoped lang="scss">
.recent-treatments {
  .user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    
    .user-name {
      font-size: 12px;
    }
  }
  
  .no-data {
    text-align: center;
    color: #909399;
    font-size: 14px;
    padding: 40px 0;
  }
}
</style>